package net.ufrog.common.weixin.pojos;

import java.io.Serializable;

import net.ufrog.common.utils.Strings;
import net.ufrog.common.utils.Strings.StringSet;
import net.ufrog.common.weixin.JsApis;

/**
 * 脚本配置
 * 
 * @author ultrafrog
 * @version 1.0, 2015-12-02
 * @since 1.0
 */
public class JsConfig implements Serializable {

	private static final long serialVersionUID = 965715094954934940L;

	/** 应用编号 */
	private String appid;
	
	/** 网址 */
	private String url;
	
	/** 随机字串 */
	private String noncestr;
	
	/** 时间戳 */
	private Long timestamp;
	
	/** 签名 */
	private String signature;
	
	/** 脚本凭证 */
	private String jsTicket;

	/** 构造函数 */
	public JsConfig() {
		this.noncestr = Strings.random(16, StringSet.NUMERIC, StringSet.LOWER_ALPHABET, StringSet.UPPER_ALPHABET);
		this.timestamp = System.currentTimeMillis();
	}
	
	/**
	 * 构造函数 
	 * 
	 * @param appid
	 * @param url
	 * @param noncestr
	 * @param timestamp
	 * @param signature
	 * @param jsTicket
	 */
	public JsConfig(String appid, String url, String jsTicket) {
		this();
		this.appid = appid;
		this.url = url;
		this.jsTicket = jsTicket;
		this.signature = JsApis.signJs(noncestr, jsTicket, timestamp, url);
	}
	
	/**
	 * 读取应用编号
	 * 
	 * @return
	 * @see #appid
	 */
	public String getAppid() {
		return appid;
	}

	/**
	 * 设置应用编号
	 * 
	 * @param appid
	 * @see #appid
	 */
	public void setAppid(String appid) {
		this.appid = appid;
	}

	/**
	 * 读取网址
	 * 
	 * @return
	 * @see #url
	 */
	public String getUrl() {
		return url;
	}

	/**
	 * 设置网址
	 * 
	 * @param url
	 * @see #url
	 */
	public void setUrl(String url) {
		this.url = url;
	}

	/**
	 * 读取随机字串
	 * 
	 * @return
	 * @see #noncestr
	 */
	public String getNoncestr() {
		return noncestr;
	}

	/**
	 * 设置随机字串
	 * 
	 * @param noncestr
	 * @see #noncestr
	 */
	public void setNoncestr(String noncestr) {
		this.noncestr = noncestr;
	}

	/**
	 * 读取时间戳 
	 * 
	 * @return
	 * @see #timestamp
	 */
	public Long getTimestamp() {
		return timestamp;
	}

	/**
	 * 设置时间戳 
	 * 
	 * @param timestamp
	 * @see #timestamp
	 */
	public void setTimestamp(Long timestamp) {
		this.timestamp = timestamp;
	}

	/**
	 * 读取签名
	 * 
	 * @return
	 * @see #signature
	 */
	public String getSignature() {
		return signature;
	}

	/**
	 * 设置签名
	 * 
	 * @param signature
	 * @see #signature
	 */
	public void setSignature(String signature) {
		this.signature = signature;
	}

	/**
	 * 读取脚本凭证
	 * 
	 * @return
	 * @see #jsTicket
	 */
	public String getJsTicket() {
		return jsTicket;
	}

	/**
	 * 设置脚本凭证
	 * 
	 * @param jsTicket
	 * @see #jsTicket
	 */
	public void setJsTicket(String jsTicket) {
		this.jsTicket = jsTicket;
	}
}
